package com.ronan.common.codec;


import com.ronan.common.protocol.IRIMProtocol;
import com.ronan.common.protocol.RIMProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;


import java.util.List;

/**
 * FileName    : com.ronan.imserver.codec
 * Description : 编码器
 *
 * @author : ysk
 * @version : 1.0
 * Create Date : 2021/2/26 0:29
 **/
@ChannelHandler.Sharable
public class RIMProtocolEncoder extends MessageToMessageEncoder<IRIMProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, IRIMProtocol protocol, List<Object> out) throws Exception {
        ByteBuf buf = ctx.alloc().buffer();
        RIMProtocol rimProtocol = (RIMProtocol) protocol;
        rimProtocol.encode(buf);
        out.add(buf);
    }
}
